<%@ page language="java" %>
<%@ page import="java.util.ArrayList,
                com.scalar.chiptrack.utils.StringUtils,
                com.scalar.chiptrack.commons.Address,
                com.scalar.chiptrack.sales.SalesOrder,
                com.scalar.chiptrack.sales.LineItem,
                com.scalar.chiptrack.utils.ConfigManager,
                com.scalar.chiptrack.operations.packingslip.forms.CommercialInvoiceForm,
                com.scalar.chiptrack.commons.Constants"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>

<chiptrack:checkLogon sourcePage="/commercialInvoice.do"/>

<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>

<HTML>
<HEAD><TITLE>ChipTrac - Commercial Invoice</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type="text/css" rel="stylesheet">
<style type="text/css">
    a { text-decoration : none}
</style>
</HEAD>
<BODY bgColor='#ffffff' leftMargin=0 topMargin=0 marginheight="0" marginwidth="0">
<table align=center width='100%' border='0'>
    <tr>
        <td colspan="4" align="right">
            <a href="javascript:window.print();" title='Click here to print this Commercial Invoice'><img src="<%=chipTracContext%>/jsp/includes/images/printer_icon_small.gif" width='80' height="50" border="0" alt=""></a>
        </td>
    </tr>
    <tr>
        <td width="30%" align="left"><img src="<%=chipTracContext%>/jsp/includes/images/scalar_logo.jpg" height="84" width="200" border=0></td>
        <td width="40%" align=center><font class='NArialW'><u>Commercial Invoice</u></font><br></td>
        <td width="25%" align=right>
            <table>
                <tr>
                    <td align="left" class="NArialL">
                        <bean:write name="commercialInvoiceForm" property="clientName" />
                        <bean:write name="commercialInvoiceForm" property="clientAddrWithOutEmailObjFormatted" filter="false"/>
                    </td>
                </tr>
            </table>
            <%--<table width='50'align=center background='<%=chipTracContext%>/jsp/includes/images/printer_icon_small.gif'>
                <tr><td><a href="javascript:window.print();" title='Click here to print this Commercial Invoice'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a>
                </td></tr>
            </table>--%>
        </td>        
    </tr>
</table>
<html:form name="commercialInvoiceForm" type="com.scalar.chiptrack.operations.packingslip.forms.CommercialInvoiceForm" action="/commercialInvoice.do?action=save">
<html:hidden name="commercialInvoiceForm" property="customerShippingId"/>
<html:hidden name="commercialInvoiceForm" property="salesOrderId"/>
<html:hidden name='commercialInvoiceForm' property='packingSlipNumber'/>
<%
    CommercialInvoiceForm commericalInvoiceForm = ( CommercialInvoiceForm ) request.getAttribute( "commercialInvoiceForm" );
    String backgroundImage = "";
    if( commericalInvoiceForm != null )
    {
        if( Constants.CUSTOMER_SHIPPING_STATUS_CANCELLED.equalsIgnoreCase( commericalInvoiceForm.getStatus() ) )
        {
            backgroundImage = chipTracContext+"/jsp/includes/images/cancelled_icon.gif";
        }
    }
    SalesOrder salesOrder = ( SalesOrder ) request.getAttribute( "salesOrder" );
    if( salesOrder != null )
    {
        Address billingAddress = salesOrder.getBillingAddressAsObject();
        Address shippingAddress = salesOrder.getShippingAddressAsObject();
%>
    <table width="95%" cellspacing='0' cellpadding='0' border=0 align=center background='<%=backgroundImage%>' >
        <tr><td colspan='5'><chiptrack:info styleClass='NArialL'/></td></tr>
        <tr><td colspan='5'><chiptrack:errors styleClass='NArialL'/></td></tr>
        <tr height=30>
            <td width="34%" class="NArialL" bgcolor="#DEE1E2" >&nbsp;Shipper :</td>
            <td width="1%" class="NArialL" bgcolor="#FFFFFF" >&nbsp;</td>
            <td width="30%" class="NArialL" bgcolor="#DEE1E2" >&nbsp;Bill To :</td>
            <td width="1%" class="NArialL" bgcolor="#FFFFFF" >&nbsp;</td>
            <td width="34%"  bgcolor="#DEE1E2"><font class="NArialL">&nbsp;Ship To :</font></td>
        </tr>
        <tr>
            <td width="34%" bgcolor='#FFFFEE'  valign="top">
                <table width='100%' class='NArialS' valign="top" >
                    <tr>
                        <td class="NArialS">
                            <bean:write  name="commercialInvoiceForm" property="clientName"/>
                            <br>
                            <bean:write name="commercialInvoiceForm" property="shipperVendorAddressAsHTML" filter="false"/>
                        </td>
                    </tr>
                </table>
            </td>
            <td width="1%" bgcolor='#FFFFFF'  valign="top"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif"></td>
            <td width="30%" bgcolor='#FFFFEE'  valign="top">
                <table width='100%' class='NArialS'>
                    <tr>
                        <td valign="top">
                            <bean:write name="commercialInvoiceForm" property="billingAddressAsHTML" filter="false"/>
                        </td>
                    </tr>
                </table>
            </td>
            <td width="1%" bgcolor='#FFFFFF' valign="top"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif"></td>
            <td width='34%' bgcolor='#FFFFEE' valign="top">
                <table width='100%'>
                    <tr>
                        <td valign="top" class="NArialS">
                            <bean:write name="commercialInvoiceForm" property="shippingAddressAsHTML" filter="false"/>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr><td colspan=5><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20></td></tr>
        <tr>
            <td colspan='5'>
                <table width='100%' border='0'>
                    <tr>
                        <logic:equal name="commercialInvoiceForm" property="isSample" value="true">
                        <td width='20%' class='NArialL' align='left'>Sample Sales Order#:</td>
                        </logic:equal>
                        <logic:notEqual name="commercialInvoiceForm" property="isSample" value="true">
                        <td width='20%' class='NArialL' align='left'>Sales Order#:</td>
                        </logic:notEqual>
                        <td width='25%'  class='NArialS' align='left'><%=salesOrder.getSalesOrderNo()%></td>
                        <td width='10%' class='NArialL' align='right'>&nbsp;</td>
                        <td width='20%' class='NArialL' align='left'>Packing Slip#&nbsp;:</td>
                        <td width='25%'  class='NArialS' align='left'><bean:write name='commercialInvoiceForm' property='packingSlipNumber'/></td>
                    </tr>
                    <tr>
                        <td width='20%' class='NArialL' align='left'><bean:message key="label.commercialInvoice.commercialInvoiceNo"/></td>
                        <td width='25%'  class='NArialS' align='left'><bean:write name='commercialInvoiceForm' property='commercialInvoiceNo'/></td>
                        <td width='10%' class='NArialL' align='right'>&nbsp;</td>
                        <td width='20%' class='NArialL' align='left'>&nbsp;</td>
                        <td width='25%'  class='NArialS' align='left'>&nbsp;</td>
                    </tr>
                    <tr>
                        <td width='20%' class='NArialL' align='left'>Ship Date:</td>
                        <td width='25%'  class='NArialS' align='left'><bean:write name='commercialInvoiceForm' property='shipDate'/></td>
                        <td width='10%' class='NArialL' align='right'>&nbsp;</td>
                        <td width='20%' class='NArialL' align='left'>Payment Terms:</td>
                        <td width='25%'  class='NArialS' align='left'><bean:write name='commercialInvoiceForm' property='shippingTerms'/></td>
                    </tr>
                    <tr>
                        <td width='20%' class='NArialL' align='left'>Way Bill :</td>
                        <td width='25%' class='NArialS' align='left'>
                        <logic:iterate name="commercialInvoiceForm" property="frieghtTrackingNumber" id="track" length="1" >
                            <bean:write name="track"/>
                        </logic:iterate>
                        </td>
                        <td width='10%' class='NArialL' align='right'>&nbsp;</td>
                        <td width='20%' class='NArialL' align='left'>Customer P.O. #&nbsp;:</td>
                        <td width='25%'  class='NArialS' align='left'><%=( ( salesOrder.getCustomerPO() == null ) || ( salesOrder.getCustomerPO().trim().length() == 0 ) ) ? "&nbsp;" : salesOrder.getCustomerPO()%></td>
                    </tr>
                    <logic:iterate name="commercialInvoiceForm" property="frieghtTrackingNumber" id="track" offset="1" >
                    <tr>
                        <td width='20%' class='NArialL' align='left'>&nbsp;</td>
                        <td width='25%' class='NArialS' align='left'>
                            <bean:write name="track"/>
                        </td>
                        <td width='10%' class='NArialL' align='right'>&nbsp;</td>
                        <td width='20%' class='NArialL' align='left'>&nbsp;</td>
                        <td width='25%'  class='NArialS' align='left'>&nbsp;</td>
                    </tr>
                    </logic:iterate>
                    <tr>
                        <td width='20%' class='NArialL' align='left'>INCOTERMS:</td>
                        <td width='25%'  class='NArialS' align='left'>
                            <bean:write name='commercialInvoiceForm' property='fob' />
                        </td>
                        <td width='10%' class='NArialL' align='right'>&nbsp;</td>
                        <td width='20%' class='NArialL' align='left'>Country of Origin(Fab):</td>
                        <td width='25%'  class='NArialS' align='left'><bean:write name='commercialInvoiceForm' property='countryOfFabOrigin' /></td>
                    </tr>
                    <tr>
                        <td width='20%' class='NArialL' align='left'>&nbsp;</td>
                        <td width='25%'  class='NArialS' align='left'>&nbsp;</td>
                        <td width='10%' class='NArialL' align='right'>&nbsp;</td>
                        <td width='20%' class='NArialL' align='left'>Country of Origin(Assy):</td>
                        <td width='25%'  class='NArialS' align='left'><bean:write name='commercialInvoiceForm' property='countryOfAssyOrigin' /></td>
                    </tr>
                   <%-- <tr>
                        <td width='20%' class='NArialL' align='left'>Loading Port:</td>
                        <td width='25%'  class='NArialS' align='left'><bean:write name='commercialInvoiceForm' property='portOfLanding' /></td>
                        <td width='10%' class='NArialL' align='right'>&nbsp;</td>
                        <td width='20%' class='NArialL' align='left'>Destination Port&nbsp;:</td>
                        <td width='25%'  class='NArialS' align='left'><bean:write name='commercialInvoiceForm' property='portOfDestination' /></td>
                    </tr>--%>
                    <tr><td colspan="5" class='NArialL' align='left'>Comments&nbsp;:</td></tr>
                    <tr>
                        <td colspan="5" class='NArialS' align='left'>
                            <bean:write name="commercialInvoiceForm" property="comments"/>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr><td colspan=5><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20></td></tR>
        <tr>
            <td colspan='5'>
                <table width="100%" border=1 cellpadding='0' cellspacing='0' bordercolor='#000000'  >
                    <tr height=30>
                        <td class="NArialL" bgcolor='#DEE1E2' align=center>PO Line Number</td>
                        <% if (ConfigManager.getBooleanProperty(ConfigManager.SHOW_MFG_PARTNO_PACKINGSLIP ) ) { %>
                        <td class="NArialL" bgcolor='#DEE1E2' align=center>
                        <bean:message key = "label.mfgPartNumber" /></td>
                        <% } %>
                        <% if (ConfigManager.getBooleanProperty(ConfigManager.SHOW_MRKT_PARTNO_PACKINGSLIP ) ) { %>
                        <td class="NArialL" bgcolor='#DEE1E2' align=center>
                        <bean:message key = "label.mktgPartNumber" /></td>
                        <% } %>
                        <td class="NArialL" bgcolor='#DEE1E2' align=center>
                            <bean:message key = "label.customerPartNumber" />
                        </td>
                        <td class="NArialL" bgcolor='#DEE1E2' align=center>Product <br>Description</td>
                        <td class="NArialL" bgcolor="#DEE1E2" align=center>Units</td>
                        <td class="NArialL" bgcolor="#DEE1E2" align=center><bean:message key="label.commercialInvoice.ScheduleNumber"/></td>
                        <td class="NArialL" bgcolor="#DEE1E2" align=center><bean:message key="label.commercialInvoice.ScheduleNumberDiscription"/></td>
                        <td class="NArialL" bgcolor="#DEE1E2" align=center><bean:message key="label.commercialInvoice.ECCN"/></td>
                        <td class="NArialL" bgcolor="#DEE1E2" align=center><bean:message key="label.commercialInvoice.LicenseSymbol"/></td>
                        <td class="NArialL" bgcolor='#DEE1E2' align=center>Shipped Qty</td>
                        <td class="NArialL" bgcolor='#DEE1E2' align=center>Unit<br>Price</td>
                        <td class="NArialL" bgcolor='#DEE1E2' align=center>Line<br>Total</td>
                    </tr>
            <%
                ArrayList lineItemList = ( ArrayList ) request.getAttribute( "lineItems" );
                float totalSalesTaxValue = 0f;
                float salesTaxValue = salesOrder.getSalesTaxValue();
                if( ( lineItemList != null ) && ( lineItemList.size() != 0 ) )
                {
                    int lineItemListSize = lineItemList.size();
                    LineItem lineItem = null;
            %>
                    <input type='hidden' name='lineItemListSize' value='<%=lineItemListSize%>'/>
            <%
                    int lineItemNumber = -1;
                    int poLineItem = -1;
                    String mktPartNumber = null;
                    String mfgPartNumber = null;
                    String description = null;
                    String scheduleNumber = null;
                    String qty = null;
                    String unitPrice = null;
                    String amount = null;
					String customerPartNumber = null;
                    String scheduleDescription = null;
                    for( int i = 0; i <= ( lineItemListSize - 1 ); i++ )
                    {
                        lineItem = ( LineItem ) lineItemList.get( i );
                        lineItemNumber     = lineItem.getLineItemNo();
                        poLineItem         = lineItem.getPoLineItemNo();
                        mfgPartNumber      = lineItem.getManufacturingPartNo();
                        mktPartNumber      = lineItem.getMarketingPartNo();
                        description        = lineItem.getDescription();
                        scheduleNumber     = lineItem.getScheduleNumber();
                        qty                = lineItem.getQtyAsString();
                        amount             = lineItem.getAmountAsString();
                        unitPrice          = lineItem.getDisplayUnitPrice();
						customerPartNumber = lineItem.getCustomerPartNumber();
                        scheduleDescription = lineItem.getScheduleDescription();
                        if( lineItem.getIsTaxable() )
                        {
                            totalSalesTaxValue += lineItem.getAmount();
                        }
            %>
                    <tr height=30>
                        <!--td bgcolor='#FFFFEE' class="NArialL" align=center nowrap><%=lineItemNumber%></td-->
                        <td bgcolor='#FFFFEE' class="NArialS" align=center nowrap>&nbsp;<%=(poLineItem < 1?"":poLineItem+"") %></td>
                        <% if (ConfigManager.getBooleanProperty(ConfigManager.SHOW_MFG_PARTNO_PACKINGSLIP ) ) { %>
                        <td bgcolor='#FFFFEE' class="NArialS" align=left nowrap>
                            <%=( ( mfgPartNumber == null ) || ( mfgPartNumber.trim().length() == 0 ) ) ? "&nbsp;" : mfgPartNumber%>
                        </td>
                        <% } if (ConfigManager.getBooleanProperty(ConfigManager.SHOW_MRKT_PARTNO_PACKINGSLIP ) ) { %>
                        <td bgcolor='#FFFFEE' class="NArialS" align=left nowrap>
                            <%=( ( mktPartNumber == null ) || ( mktPartNumber.trim().length() == 0 ) ) ? "&nbsp;" : mktPartNumber%>
                        </td>
                        <% } %>
                        <td bgcolor='#FFFFEE' class="NArialS" align=left nowrap>
                            <%=( ( customerPartNumber == null ) || ( customerPartNumber.trim().length() == 0 ) ) ? "&nbsp;" : customerPartNumber %>
                        </td>
                        <td bgcolor='#FFFFEE' class="NArialS" align=left width='240'>
                            <%=( ( description == null ) || ( description.trim().length() == 0 ) ) ? "&nbsp;" : description%>
                        </td>
						<td bgcolor="#FFFFEE" class="NArialL" align=right nowrap><%=( ( lineItem.getUom() == null ) || ( lineItem.getUom().trim().length() == 0 ) ) ? "&nbsp;" : lineItem.getUom()%></td>
						<td bgcolor='#FFFFEE' class="NArialS" align=center nowrap>
                            <%=lineItem.getScheduleNumber()%>
                        </td>
                       <td bgcolor='#FFFFEE' class="NArialS" align=center nowrap>
                            <%=lineItem.getScheduleDescription()%>
                        </td>
                        <td bgcolor='#FFFFEE' class="NArialS" align=center nowrap>
                            <%=lineItem.getEccn()%>
						</td>
						<td bgcolor='#FFFFEE' class="NArialS" align=center nowrap>
                            <%=( ( lineItem.getLicenseException() == null ) || ( lineItem.getLicenseException().trim().length() == 0 ) ) ? "&nbsp;" : lineItem.getLicenseException()%>
						</td>
                        <td bgcolor='#FFFFEE' class="NArialS" align=right nowrap>
                            <%=( ( qty == null ) || ( qty.trim().length() == 0 ) ) ? "&nbsp;" : qty%>
                        </td>
                        <td bgcolor='#FFFFEE' class="NArialS" align=right nowrap>
                            <%=( ( unitPrice == null ) || ( unitPrice.trim().length() == 0 ) ) ? "&nbsp;" : unitPrice%>
                        </td>
                        <td bgcolor='#FFFFEE' class="NArialS" align=right nowrap>
                            <%=( ( amount == null ) || ( amount.trim().length() == 0 ) ) ? "&nbsp;" : amount%>
                        </td>
                    </tr>
            <%
                    }
                }
            %>
                    <tr>
                        <td colspan='9' align=center><font class='NArialS'><br>NOTE: THE VALUE SHOWN IS FOR CUSTOMS PURPOSE ONLY.</font></td>
                        <td colspan='3'>&nbsp;</td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td colspan=5 bgcolor='#DEE1E2' align="right" valign=top>
                <font class='NArialL'>
                    Grand Total: <%=StringUtils.formatAmountWithNoOfDecimals((salesOrder.getSubTotalAsDouble() ))%>
                </font>
            </td>
        </tr>
        <tr><td colspan=5><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20></td></tr>
        <tr>
            <td colspan=5>
                <table width='100%' border='0'>
                    <tr>
                        <td width='20%' class='NArialL' align='right'>TOTAL PKGS:</td>
                        <td width='5%'  class='NArialS' align='center'><bean:write name='commercialInvoiceForm' property='totalPackagesStr'/></td>
                        <td width='5%' class='NArialL' align='right'>&nbsp;</td>
                        <td width='40%' class='NArialL' align='right'>&nbsp;</td>
                        <td width='20%' class='NArialL' align='right'><!-- License Symbol: -->&nbsp;</td>
                        <td width='5%'  class='NArialS' align='left'><!-- < b e a n : w r i t e name='commercialInvoiceForm' property='licens eSy mbol' / > -->&nbsp;</td>
                    </tr>
                    <tr>
                        <td width='20%' class='NArialL' align='right'>
                            <% if( ConfigManager.getShowPackageDimensionInPackingSlip() ) { %>
                            NET WEIGHT:
                            <% } else { %>
                            WEIGHT:
                            <% } %>
                        </td>
                        <td width='5%'  class='NArialS' align='center'><bean:write name='commercialInvoiceForm' property='totalWeight'/></td>
                        <td width='5%' class='NArialL' align='left'>
                            &nbsp;&nbsp;
                            <logic:notEqual value="" name="commercialInvoiceForm" property="totalWeight">
                            <bean:write name='commercialInvoiceForm' property='weightType'/>
                            </logic:notEqual>
                            &nbsp;
                        </td>
                        <td width='45%' class='NArialL' align='right'>&nbsp;</td>
                        <td width='20%' class='NArialL' align='right'><!-- ECCN: -->&nbsp;</td>
                        <td width='5%'  class='NArialS' align='left'><!-- < b ea n : wr i t e  n a m e= 'c o mmercialInvoiceForm' property='eccn' / > -->&nbsp;</td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr><td colspan=5><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20></td></tR>
        <tr>
            <td colspan=5>
                <table width='100%' cellpadding='0' cellspacing='0' border='1' bordercolor='#000000' >
                    <tr>
                        <td class='NArialS'>
                            These commodities, technology, or software were exported from the United States in accordance<br>
                            with the Export Administration regulations. Diversion contrary to U.S. law is prohibited.
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr><td colspan=5><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=25></td></tR>
        <tr>
            <td colspan='5'>
                <table border='0' width='100%' >
                    <tr>
                        <td width='15%' class='NArialL' align="center" valign="bottom">Signature:</td>
                        <td width='50%' class='signatureGray' align=left>
                            &nbsp;&nbsp;&nbsp;&nbsp;
                            <bean:message key="label.signature"/>
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        </td>
                        <td width='5%'  class='NArialL' align=center>&nbsp;</td>
                        <td width='10%' class='NArialL' align="center" valign="bottom">Date:</td>
                        <td width='20%' class='signature' align=center>&nbsp;</td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr><td colspan=5><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=25></td></tR>
    </table>
    <%
        }
    %>
</html:form>
</body>
</html>
